package com.zjk.storage.core.provider;


import cn.hutool.core.util.StrUtil;
import com.zjk.storage.core.entity.BaseFileInfo;
import com.zjk.storage.core.entity.UploadPretreatment;
import com.zjk.storage.core.exception.FileStorageException;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;

import java.io.IOException;
import java.io.InputStream;
import java.util.function.Consumer;

public interface FileStorage {

    String getPlatform();

    boolean upload(BaseFileInfo fileInfo, UploadPretreatment pre);

    /**
     * 删除文件
     */
    boolean delete(BaseFileInfo fileInfo);

    /**
     * 文件是否存在
     */
    boolean exists(BaseFileInfo fileInfo);

    /**
     * 下载文件
     */
    void download(BaseFileInfo fileInfo, Consumer<InputStream> consumer);

    /**
     * 下载缩略图文件
     */
    void downloadTh(BaseFileInfo fileInfo, Consumer<InputStream> consumer);

    default String getFileKey(BaseFileInfo fileInfo) {
        return StrUtil.addSuffixIfNot(fileInfo.getBasePath(), StrUtil.EMPTY)
                + StrUtil.addSuffixIfNot(fileInfo.getPath(), StrUtil.EMPTY)
                + StrUtil.addSuffixIfNot(fileInfo.getFileName(), StrUtil.EMPTY);
    }
}
